package com.dms.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dms.modules.system.entity.RoleUser;
import com.dms.modules.system.mapper.RoleUserMapper;
import com.dms.modules.system.service.RoleUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * 角色用户关联服务实现类
 */
@Service
@Slf4j
public class RoleUserServiceImpl extends ServiceImpl<RoleUserMapper, RoleUser> implements RoleUserService {

    @Autowired
    private RoleUserMapper roleUserMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteRolesByUserIdAndType(Long userId, Integer userType) {
        try {
            LambdaQueryWrapper<RoleUser> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(RoleUser::getUserId, userId)
                   .eq(RoleUser::getUserType, userType);
            return remove(wrapper);
        } catch (Exception e) {
            log.error("删除用户角色关联失败 userId={}, userType={}", userId, userType, e);
            return false;
        }
    }
} 